package grad.nxu.recruitsystem.controller;

import grad.nxu.recruitsystem.service.BiographicalNotesService;
import grad.nxu.recruitsystem.vo.ApiResponse;
import grad.nxu.recruitsystem.vo.BiographicalNotesVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: HAPPY
 * @Project_name: recruitSystem
 * @Package_name: grad.nxu.recruitsystem.controller
 * @Date: 2023/3/13 11:08
 * @Description:
 */
@RestController
@RequestMapping("/api/v1/biographical_notes")
public class BiographicalNotesController {
    @Autowired
    BiographicalNotesService biographicalNotesService;

    /**
     * 管理员获取所有简历接口
     * @param pageSize 每页多少条
     * @param pageNumber 第几页
     * @return 返回简历列表
     */
    @ApiOperation("管理员获取所有简历接口")
    @GetMapping("/admin/all")
    public ApiResponse<List<BiographicalNotesVO>> getAll(Integer pageSize, Integer pageNumber) {
        ApiResponse<List<BiographicalNotesVO>> apiResponse = new ApiResponse<>();
        try {
            List<BiographicalNotesVO> biographicalNotesVOList = biographicalNotesService.getByPage(pageSize, pageNumber);
            apiResponse.setData(biographicalNotesVOList).setSuccess(true).setCode(200);
        } catch (Exception e) {
            apiResponse.setCode(500).setSuccess(false).setMessage("服务器异常");
        }
        return apiResponse;
    }

    /**
     * 删除简历接口，会级联删除对应的教育经历和工作经历
     * @param id 简历id
     * @return 返回删除结果
     */
    @ApiOperation("删除简历接口，会级联删除对应的教育经历和工作经历")
    @DeleteMapping("/delete")
    public ApiResponse<String> deleteById(Integer id) {
        ApiResponse<String> apiResponse = new ApiResponse<>();
        try {
            biographicalNotesService.removeById(id);
            apiResponse.setMessage("删除成功").setCode(200).setSuccess(true);
        } catch (Exception e) {
            apiResponse.setSuccess(false).setCode(500).setMessage("删除失败");
        }
        return apiResponse;
    }


}
